package player;

import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;
import javazoom.jl.player.advanced.AdvancedPlayer;
import javazoom.jl.player.advanced.PlaybackEvent;
import javazoom.jl.player.advanced.PlaybackListener;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class MyPlayerThread extends Thread{
    boolean isPause=false;
    private int pausedOnFrame=0;
    File file;
    AdvancedPlayer player;
    static File fileList[]=new File[100];
    public MyPlayerThread(String filepath){
        file=new File(filepath);
    }
    public MyPlayerThread(String songList[]){
        for(int i=0;i<songList.length;i++){
            fileList[i]=new File(songList[i]);
        }
    }
    public void run(){

        if(isPause==false) {
            for (int i = 0; i < fileList.length; i++) {
                try {
                    FileInputStream fis = new FileInputStream(fileList[i]);
                    BufferedInputStream stream = new BufferedInputStream(fis);
                    player = new AdvancedPlayer(stream);
                    player.setPlayBackListener(new PlaybackListener() {
                        @Override
                        public void playbackFinished(PlaybackEvent evt) {
                            pausedOnFrame = evt.getFrame();
                        }
                    });
                    player.play();
                    isPause = true;
                } catch (FileNotFoundException e1) {
                } catch (JavaLayerException e2) {
                }
            }
        }

    }
    public void pause(){
        player.stop();
    }
}
